<%--
  Created by IntelliJ IDEA.
  User: leixiaolong
  Date: 2018/9/13
  Time: 下午6:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="/static/css/rpt-condition.css" media="all" type="text/css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/layui/css/layui.css" media="all"
          type="text/css">
    <style>
        .layui-table-header {
            background-color: #1E9FFF;
        }

        .layui-table thead tr {
            background-color: #1E9FFF;
            color: black;
        }
    </style>
</head>
<body>
<div style="padding: 10px;">
    <div class="layui-form" style="border-color: black; border-style: solid; border-width: 1px;" lay-filter="select-condition">
        <div style="height: 20%; margin-top: 15px;">
            <div>
                <div>
                    <div class="layui-form-item layui-input-inline">
                        <label class="layui-form-label">交易起始日期：</label>
                        <input type="text" class="layui-input-inline dom-input" id="exch_start_date"
                               placeholder="yyyy-MM-dd">
                    </div>
                    <div class="layui-form-item layui-input-inline">
                        <label class="layui-form-label">交易结束日期：</label>
                        <input type="text" class="layui-input-inline dom-input" id="exch_end_date"
                               placeholder="yyyy-MM-dd">
                    </div>

                    <div class="layui-form-item layui-input-inline layui-hide">
                        <label class="layui-form-label">销售单起始日期：</label>
                        <input type="text" class="layui-input-inline dom-input" id="sale_start_date" placeholder="yyyy-MM-dd">
                    </div>
                    <div class="layui-form-item layui-input-inline layui-hide">
                        <label class="layui-form-label">销售单结束日期：</label>
                        <input type="text" class="layui-input-inline dom-input" id="sale_end_date" placeholder="yyyy-MM-dd">
                    </div>

                    <div class="layui-form-item layui-input-inline">
                        <label class="layui-form-label">销售客户代码：</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input-inline dom-add-input" id="cust_code">
                        </div>
                    </div>

                    <div class="layui-form-item layui-input-inline">
                        <label class="layui-form-label">销售客户名称：</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input-inline dom-add-input" id="cust_name">
                        </div>
                    </div>

                    <div class="layui-form-item layui-input-inline">
                        <label class="layui-form-label">销售类型：</label>
                        <div class="layui-input-inline">
                            <select class="layui-form-select" id="sale_type" lay-filter="sale_type">
                                <option value="" selected>全部</option>
                            </select>
                        </div>
                    </div>
                    <%--<div class="layui-form-item layui-input-inline">--%>
                        <%--<label class="layui-form-label">源订单类型：</label>--%>
                        <%--<div class="layui-input-inline">--%>
                            <%--<select class="layui-form-select" id="sour_bill_Type">--%>
                                <%--<option value="" selected>全部</option>--%>
                            <%--</select>--%>
                        <%--</div>--%>
                    <%--</div>--%>
                </div>
            </div>
        </div>
        <div style="float: right; margin-right: 6%; margin-top: -50px;">
            <button class="layui-btn layui-btn-normal layui-btn-radius" lay-submit data-type="search">搜索</button>
            <button class="layui-btn layui-btn-warm layui-btn-radius" style="margin-right: 20px;">重置</button>
        </div>
        <div style="clear:both"></div>
    </div>

    <div class="layui-btn-group" style="float: right; margin-right: 100px; margin-top: 5px;">
        <button class="layui-btn layui-btn-sm layui-btn-primary" lay-submit lay-filter="btn-add-filt">新增</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary">导出</button>
    </div>

    <div style=" background-color: white; margin-top: 35px;">
        <table class="layui-hide" id="tab_market_apply" lay-filter="sale-table-filter"></table>
    </div>
</div>
</body>
</html>

<script type="text/html" id="selaEdit">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script language='javascript' src="${pageContext.request.contextPath}/plugins/layui/layui.js"></script>
<script language='javascript' src="${pageContext.request.contextPath}/static/js/component/form-select.js"></script>
<script language='javascript' src="${pageContext.request.contextPath}/static/js/component/form-date.js"></script>
<script language='javascript' src="${pageContext.request.contextPath}/static/js/utils/moment.js"></script>

<script>
    layui.use(["form", "element", "jquery", "layer", "laydate", "table"], function () {
        var form = layui.form, element = layui.element, layer = layui.layer, $ = layui.jquery;
        var laydate = layui.laydate, table = layui.table;

        var nowdate = moment().format('YYYY-MM-DD');
        renderDate('exch_start_date' , nowdate);
        renderDate('exch_end_date' , nowdate);
        renderDate('sale_start_date' , nowdate);
        renderDate('sale_end_date' , nowdate);
        var params = {
            sysCode : '12'
        };
        // var params1 = {
        //     sysCode : '13'
        // };
        initCodeTableSelect("sale_type","/base/getSysCodeList",params);
        // initCodeTableSelect("sour_bill_Type","/base/getSysCodeList",params1);

        var tableIns = table.render({
            elem: '#tab_market_apply',
            url: '/sale/getMarketSaleList',
            where: {
                exchStartDate: $('#exch_start_date').val(),
                exchEndDate: $('#exch_end_date').val(),
                saleStartDate: $('#sale_start_date').val(),
                saleEndDate: $('#sale_end_date').val(),
                custCode: $('#cust_code').val(),
                custName: $('#cust_name').val(),
                saleType: $('#sale_type').find('OPTION:selected').val(),
                sourBillType: $('#sour_bill_Type').find('option:selected').val(),
            },
            height: 'full-230',
            cols: [[
                {field: 'id', title: '销售单id', type: 'numbers', align: 'center'},
                // {field: 'compCode', title: '企业编码', align: 'center'},
                {field: 'saleType', title: '销售类型', align: 'center',
                    templet: function(row){
                        if(typeof(row.saleType) === 'undefined' || null == row.saleType){
                            return '-';
                        }
                        switch (row.saleType){
                            case '1':
                                return '现销';
                            case '2':
                                return '赊销';
                            case '3':
                                return '分期收款';
                            case '4':
                                return '委托代销';
                            case '5':
                                return '受托代销'
                            default:
                                return row.saleType;
                        }
                    }
                },
                // {field: 'sourBillType', title: '源订单类型', align: 'center',
                //     templet: function(row){
                //         if(typeof(row.sourBillType) === 'undefined' || null == row.sourBillType){
                //             return '-';
                //         }
                //         switch (row.sourBillType){
                //             case '1':
                //                 return '销售追加';
                //             case '2':
                //                 return '销售新增'
                //             default:
                //                 return row.sourBillType;
                //         }
                //     }
                // },
                {field: 'custName', title: '销售客户名称', align: 'center'},
                {field: 'sourBillId', title: '源订单id', align: 'center'},
                // {field: 'linkMan', title: '客户联系人名称', align: 'center'},
                // {field: 'linkManTel', title: '客户联系人电话', align: 'center'},
                // {field: 'userId', title: '经办人', align: 'center'},
                // {field: 'saleDate', title: '销售单日期', align: 'center'},
                {field: 'exchDate', title: '交易日期', align: 'center'},
                {field: 'verfyStat', title: '审核状态', align: 'center',
                    templet: function(row){
                        switch (row.verfyStat){
                            case '0':
                                return '待提交审核';
                            case '1':
                                return '待审核';
                            case '2':
                                return '审核通过';
                            case '3':
                                return '审核未通过';
                            case '4':
                                return '反审核';
                            default:
                                return row.verfyStat;
                        }
                    }
                },
                {field: 'verfyErrMsg', title: '审核失败原因', align: 'center'},,
                {
                    field: 'opertaor', title: '操作', align: 'center', templet: '#selaEdit', fixed: 'right'
                }
            ]],
            done: function () {
                var myDate = new Date();
                table.on('rowDouble', function(obj){
                    var rowdata = obj.data;
                    layer.open({
                        id: 'detail-form',
                        type: 2,
                        shadeClose: true,
                        shade: false,
                        maxmin: true,
                        content: "/sale/market_sale_detail",
                        title: ['销售单明细', 'text-align: center; font-size: 20px;'],
                        area: ['1500px', '750px'],
                        success:function (data) {
                            var iframeId = document.getElementById('detail-form').getElementsByTagName('iframe')[0].id;
                            $('#'+ iframeId)[0].contentWindow.init(rowdata);
                        }
                    });
                });
                layer.msg("数据渲染完成, date:" + myDate.getSeconds());
            },
            page: true
            // page: {
            //     limit: 20,
            //     limits: [10, 20, 50]
            // }
        });

        table.on('tool(sale-table-filter)', function(obj){
            var rowdata=obj.data;  //获取当前行数据
            var layEvent = obj.event;   //获取事件名称
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if(layEvent == 'edit'){
                layer.open({
                    id: 'edit-form',
                    type: 2,
                    title: ['销售单修改', 'text-align: center; font-size: 20px;'],
                    area: ['1500px', '750px'],
                    offset: 'auto',
                    content: '/sale/market_sale_update',
                    success: function(){
                        var iframeId = document.getElementById('edit-form').getElementsByTagName('iframe')[0].id;
                        $('#'+ iframeId)[0].contentWindow.init(rowdata);
                    }
                });

            }else if(layEvent == 'del'){
                var param = {id: rowdata.id };
                layer.confirm("是否删除本条记录", {icon: 3}, function (index) {
                    $.ajax({
                        type: 'POST',
                        url: '/sale/marketSaleDel',
                        data: param,
                        success: function(data){
                            layer.msg("销售单删除成功！");
                        },
                        fail: function(data){
                            layer.msg("销售单删除失败：" + data.data.rspMsg);
                        }
                    });
                    layer.close(index);
                });
            }
        });

        form.on('submit(btn-add-filt)', function () {
            layer.msg("打开新增页面");
            layer.open({
                type: 2,
                title: ['销售单录入', 'text-align: center; font-size: 20px;'],
                area: ['1500px', '750px'],
                offset: 'auto',
                content: '/sale/market_sale_add',
            });
        });

        var actives = {
            search: function(){
                tableIns.reload({
                    where: {
                        orderId: '',
                        exchStartDate: $('#exch_start_date').val(),
                        exchEndDate: $('#exch_end_date').val(),
                        saleStartDate: $('#sale_start_date').val(),
                        saleEndDate: $('#sale_end_date').val(),
                        saleType: $('#sale_type').find('OPTION:selected').val(),
                        // sourBillType: $('#sour_bill_Type').find('option:selected').val(),
                        custCode: $('#cust_code').val(),
                        custName: $('#cust_name').val()
                    }
                });
            },
            reset: function(){
                layer.msg("reset runing");
            }
        };

        form.on('submit', function(data){
            actives[$(this).data("type")].call(this);
        });

    });

    function reloadTable(){
        layui.use(['table', 'jquery'], function(){
            var table=layui.table, $=layui.jquery;
            table.reload('tab_market_apply', {
                where: {
                    makerId: '',
                    exchStartDate: $('#exch_start_date').val(),
                    exchEndDate: $('#exch_end_date').val(),
                    saleStartDate: $('#sale_start_date').val(),
                    saleEndDate: $('#sale_end_date').val(),
                    saleType: $('#sale_type').find('OPTION:selected').val(),
                    // sourBillType: $('#sour_bill_Type').find('option:selected').val(),
                    custCode: $('#cust_code').val(),
                    custName: $('#cust_name').val()
                }
            });
        })
    }
</script>
